<?php
/**
 * 登录信息
 * PHP version 7
 *
 * @address   Pay
 * @package   App\Http\Controllers\Pay
 * @author    zhengys <zhengys@boqii.net>
 * @copyright 2016-2019 guangcheng Co. All Rights Reserved.
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
 * @version   GIT:<git_id>
 * @link      http://shop.openapi.boqii.com
 */

namespace App\Http\Controllers\Supplier;

use Log;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Support\Collection;
use Illuminate\Http\Request;
use App\Models\Supplier\Supplier;

/**
 * 登录信息
 * Class Login
 *
 * @packageApp\Models\Supplier\Supplier
 */
class LoginController extends Controller
{
	/**
     * @var App\Models\Supplier\Supplier
    */
    private $model;
	
	/**
     * LoginController constructor.
     *
     * @param \App\Models\Common\Login
     */
    public function __construct(Supplier $supplier)
    {
        $this->model = $supplier;
    }
	/**
	 * 登录接口
	 *
	 * @param Request $request
     * @param int     $id
     * @param string  $version
     * @access public
     * @return mixed
     */
	public function loging(Request $request, int $id, string $version = '1.0') : Collection
    {
		$messages = [
			'required' => ':attribute 的字段是必要的'
		];
		$rules = [
			'LoginName' => $request->input('LoginName'),
			'LoginName' => 'required',
            'LoginPass' => $request->input('LoginPass'),
			'LoginPass' => 'required'
		];
		$validator = Validator::make($request->input(),$rules,$messages);
        if ($validator->fails()) 
		{
            $this->throwValidationException($request, $validator);
        }
		$result = $this->model->Loging($request->all());
		if(!empty($result)){
			$ret['SupplierId'] = authcode($result['id'],'ENCODE');
		}else{
			$ret = [];
		}
        return collect(['List'=>$ret]);
	}
	
	
}